//
//  AzirRPCService.Upload.swift
//  Center_RPC
//
//  Created by 蒋晨成 on 2022/2/16.
//

import Center_Core_Model
import Foundation
import GRPC

public extension AzirRPCService {
    func getUploadToken(bizType: Int64, complete: @escaping (Result<Azir_Gateway_GetUploadTokenResponse, Error>) -> Void) {
        requestQueue.async { [self] in
            let client = Azir_Gateway_UploadClient(channel: self.connection, defaultCallOptions: self.callOptions(), interceptors: AzirClientInterceptorFactory())
            let call = client.getUploadToken(.with {
                $0.bizType = bizType
                $0.guid = context.guid
            })
            call.response.whenComplete { result in self.resultQueue.async { complete(result) } }
            do {
                let status = try call.status.wait()
                self.logger.info("Call Status : \(status)")
            } catch {
                self.logger.error("Call Failed With Error : \(error)")
            }
        }
    }
}
